<template>
	<view class="bindingPhone-container">
		<view class="title">绑定手机号</view>
		<view class="desc">登录账号前，请先绑定手机号</view>
		<view class="input-box mb-16">
			<u-input v-model="pageForm.phone" type="number" maxlength="11" height="44" placeholder="请输入手机号" placeholder-style="color: #808080;" />
		</view>
		<view class="input-box">
			<u-input v-model="pageForm.code" type="number" maxlength="6" height="44" placeholder="短信验证码"  placeholder-style="color: #808080;" />
			<text @click="getCode" v-if="showGetCode" class="sendCode-text">发送</text>
			<u-verification-code v-show="false" :seconds="seconds" ref="uCode" @change="codeChange" change-text="x" end-text="0"></u-verification-code>
			<text class="sendCode-text" v-if="!showGetCode">{{ tips }}秒重新获取</text>
		</view>
		<view @click="toNext" class="btn-box">下一步</view>
	</view>
</template>

<script setup>
import { ref } from 'vue';

const pageForm = ref({
	phone: '',
	code: ''
});

// 获取验证码
const showGetCode = ref(true);
const uCode = ref(null); // 验证码倒计时组件实例
const getCode = () => {
	if (uni.$u.test.mobile(pageForm.value.phone)) {
		uni.showLoading({
			title: '正在获取验证码'
		});
		getPhoneCode();
	} else {
		uni.showToast({
			title: '请输入正确的手机号',
			icon: 'none'
		});
	}
};

// 获取验证码
const getPhoneCode = async () => {
	setTimeout(() => {
		uni.hideLoading();
		showGetCode.value = false;
		uCode.value.start();
	}, 1500);
	return;
	let res = await getVerificationCode({
		phoneNumber: loginForm.value.phone,
		sendType: '4'
	});
	uni.hideLoading();
	if (res.code == 200) {
		uCode.value.start();
		showGetCode.value = false;
		uni.showToast({
			title: '验证码已发送',
			icon: 'none'
		});
	}
};

// 验证码倒计时变化
const tips = ref('');
const seconds = ref('60');
const codeChange = (text) => {
	console.log(text);
	tips.value = text;
	if (tips.value < 1) {
		showGetCode.value = true;
		uCode.value.reset();
	}
};

// 下一步
const toNext = () => {
	uni.navigateTo({
		url: '/subPages/bindingInviteCode/index'
	})
};
</script>

<style lang="scss" scoped>
.bindingPhone-container {
	padding: 42px 20px;

	.title {
		font-weight: 600;
		font-size: 26px;
		line-height: 36px;
		margin-bottom: 8px;
	}

	.desc {
		color: #999;
		font-size: 14px;
		line-height: 20px;
		margin-bottom: 82px;
	}

	.input-box {
		display: flex;
		justify-content: space-between;
		padding: 20px;
		font-size: 22px;
		border-radius: 12px;
		background-color: #f5f7fb;

		.sendCode-text {
			font-size: 16px;
		}
	}
	
	.btn-box {
		display: flex;
		align-items: center;
		justify-content: center;
		color: #fff;
		width: 100%;
		height: 52px;
		font-weight: 500;
		font-size: 16px;
		margin-top: 60px;
		border-radius: 34px;
		background: linear-gradient(90deg, #FF0309 0%, #FF6C2A 100%);
	}
}
</style>
